/**
 *  TinyPasswordManager
 *  Copyright (C) 2008 Gross David <gdavid.devel@gmail.com>
 *                     Vinet Guillaume <vinet.guillaume@gmail.com>
 *
 *  This program is free software: you can redistribute it and/or modify
 *  it under the terms of the GNU General Public License as published by
 *  the Free Software Foundation, either version 3 of the License, or
 *  (at your option) any later version.
 *
 *  This program is distributed in the hope that it will be useful,
 *  but WITHOUT ANY WARRANTY; without even the implied warranty of
 *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 *  GNU General Public License for more details.
 *
 *  You should have received a copy of the GNU General Public License
 *  along with this program.  If not, see <http://www.gnu.org/licenses/>.
*/

#ifndef IDENTIFIERTABLE_H
#define IDENTIFIERTABLE_H

#include <QTableWidget>
#include <QTranslator>

#include <identifier.h>

class QAction;
class QSignalMapper;

namespace Ui {
    class IdentifierTable;
}

/*!
 * \class IdentifierTable
 * \brief Qt GUI Table for displaying Identifiers
 *
 * This class represent a table to display TinyPasswordManager database content
 * Implements a right click menu and send signals corresponding to a selected action in it.
 * Extends QTableWidget class
 *
 * \author Vinet Guillaume <vinet.guillaume@gmail.com>
 * \date 07/01/2009
 */
class IdentifierTable : public QTableWidget
{
    Q_OBJECT

public:
    //! Create a IdentifierTable object.
    /*!
     * \param parent the QWidget object parent.
     */
    IdentifierTable(QWidget *parent);

    //! Destroy a IdentifierTable object.
    virtual ~IdentifierTable();

    //! Get a row cells content.
    /*!
     * \param index table row.
     * \return Identifier object.
     */
    Identifier getIdentifier(int index);

    //! Replace a row cells content.
    /*!
     * \param index table row.
     * \param id Identifier object to replace with.
     */
    void setIdentifier(int index, const Identifier &id);

    //! Add a new row with provided content.
    /*!
     * \param id Identifier object to add in the table
     */
    void addIdentifier(Identifier id);

    //! Remove a row.
    /*!
     * \param index table row.
     */
    void removeIdentifier(int index);
    
    //! Translate the GUI in the specified language.
    /*!
     * \param language the language.
     */
    void translate(const QString &language);

protected:
    //! Capture mouse right click event and display a menu.
    /*!
     * \param event Internal event from Qt.
     */
    void contextMenuEvent(QContextMenuEvent *event);

    //! Capture event from the keyboard.
    /*!
     * \param event the keyboard event.
     */
    void keyPressEvent(QKeyEvent *event);

private:
    //! Edit item from context menu.
    QAction *m_editAction;

    //! Copy password item from context menu.
    QAction *m_copyAction;

    //! Delete item from context menu.
    QAction *m_deleteAction;

    //! Translator.
    QTranslator *m_translator;
    
    //! Load images for GUI components.
    void setIcons();

    //! Create connections between GUI components.
    void createConnections();

    //! Initialize the first state after components creation for the window.
    void init();

signals:
    //! Signal emited when edit item is clicked
    void edit();

    //! Signal emited when copy password item is clicked
    void copyPassword();

    //! Signal emited when remove item is clicked
    void remove();

    //! Signal emited when a key is pressed
    void keyEvent(QKeyEvent *event);
};

#endif
